<?php

/*===============微信商城=================*/
/*----------------------------------------*/
/* $Author: 疯中追风                      */
/*----------------------------------------*/
/* $Time: 2017/10/12 10:18                */
/*----------------------------------------*/
/*===============搜索页面=================*/

namespace Home\Controller;
use Think\Controller;
class SearchController extends Controller{

	/*搜索商品方法*/
	public function search(){
		$model = M('Goods');
		if(IS_POST){
			//获取搜索的值
			$q = I('post.search');
			session('query',$q);
			//默认排序
			$result1= $model -> where("goods_name like '%$q%' ") -> order('id desc') -> select();
			//销量排序
			$result2 = $model-> where("goods_name like '%$q%' ") -> order('sales desc') -> select();
			//价格降序
			$result3= $model -> where("goods_name like '%$q%' ") -> order('local_price desc') -> select();
			//推荐排序（时间排序）
			$result4= $model -> where("goods_name like '%$q%' ") -> order('id asc') -> select();
		}else{
			$q = I('get.q');
			session('query',$q);
			//默认排序
			$result1= $model -> where("goods_name like '%$q%' ") -> order('id desc') -> select();
			//销量排序
			$result2 = $model-> where("goods_name like '%$q%' ") -> order('sales desc') -> select();
			//价格降序
			$result3= $model -> where("goods_name like '%$q%' ") -> order('local_price desc') -> select();
			//推荐排序（时间排序）
			$result4= $model -> where("goods_name like '%$q%' ") -> order('id asc') -> select();
		}
		//获取
		$this -> assign('query',$query);
		$this -> assign('result1',$result1);
		$this -> assign('result2',$result2);
		$this -> assign('result3',$result3);
		$this -> assign('result4',$result4);
		$this -> display();
	}

	//更改价格排序
	public function  price_sort(){
		$sort = I('get.sort');
		$q = session('query');
		if($sort){
			$result3= M('Goods') -> where("goods_name like '%$q%' ") -> order('local_price asc') -> select();
		}else{
			$result3= M('Goods') -> where("goods_name like '%$q%' ") -> order('local_price desc') -> select();
		}
	   	$this -> assign("result3",$result3);
	   	$this -> display();
	}
	 //错误提示信息
    public function _empty(){
        echo "您访问的页面不存在！";
    }

}
?>